﻿using Autofac;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BCVP.Net8.Extension.autofac
{
    public class AutofacPropertityModuleReg : Module
    {
        /// <summary>
        /// 意味着 Autofac 会自动为控制器类的公共属性注入依赖项，而不需要通过构造函数注入
        /// 依赖属性的形式: public IBaseService<Role, RoleVo> _roleServiceObj { get; set; }
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            var controllerBaseType = typeof(ControllerBase);
            builder.RegisterAssemblyTypes(typeof(Program).Assembly)
                .Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType)
                .PropertiesAutowired();
        }
    }

}
